function shellSort(arr) {
    var n = arr.length;
    var gap = 1;
    while (gap < n / 3) {
        gap = 3 * gap + 1;
    }
    while (gap > 0) {
        for (var i = gap; i < n; i++) {
            var temp = arr[i];
            var j;
            for (j = i; j >= gap && arr[j - gap] > temp; j -= gap) {
                arr[j] = arr[j - gap];
            }
            arr[j] = temp;
        }
        gap = (gap - 1) / 3;
    }
    return arr;
}

function test() {
    var arr = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5];
    console.log(shellSort(arr));
}

test();
